C     Program EX_0604.FOR
C     Listing 13F - see documentation in TUTOR.SSS
 
$include:'SSSF1.H'
 
      subroutine prime
$include:'SSSF2.H'
      integer ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server
      real*8 ORDNRY, DELUX
      common ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server, ORDNRY, DELUX
 
      id     = 0
      server = 2
      ARRIVL = 1
      STARTA = 2
      ENDACT = 3
      NEXTAC = 4
      ORDNRY = 0.0
      DELUX  = 1.0

      call INIQUE(2, 3, 1)
      call inista(1,'Interrupts           ',0,0,0,0)
      call SIMEND(60.0)
      call CREATE(0.0, 0)
      return
      end

      subroutine preemp
$include:'SSSF2.H'
 
      integer ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server
      real*8 ORDNRY, DELUX
      common ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server, ORDNRY, DELUX
      real*8 remt
 
      call QUEUE(2, 0.0)
      i = 1
  99  continue
      if ((i.le.NC()).and.
     +  ((AIC(i, 3).eq.DELUX).or.(NEIC(i).ne.ENDACT)))
     +  then
        i = i + 1
        goto 99
      endif
 
      if (i.le.NC()) then
        remt = TIC(i) - T()
        call REMVFC(i)
        call SETA(1, A(1) + 1.0)
        call SETA(2, remt)
 
        call SETQDC(1, 'LIFO    ')
        call QUEUE(1, 0.0)
        call SETQDC(1, 'FIFO    ')
        call REMVFQ(2, 1)
        call SCHED(0, STARTA, IDE())
      endif
      return
      end
 
      Program EX_0604
$include:'SSSF2.H'
      integer ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server
      real*8 ORDNRY, DELUX
      common ARRIVL, STARTA, ENDACT, NEXTAC,
     +  id, server, ORDNRY, DELUX
      integer ecode
 
      call prime
 
   99 ecode = NEXTEV()
      if (ecode.gt.0) then
        goto (101, 102, 103, 104) ecode
 
C ARRIVL
  101   continue
        id = id + 1
        call CREATE(EX(2.0), id)
        call SETA(1, 0.0)
        call SETA(2, TR(1.0, 2.0, 3.0))
 
        if (RA().lt.0.25) then
          call SETA(3, DELUX )
        else
          call SETA(3, ORDNRY)
        endif
        call SCHED(0.0, NEXTAC, IDE())
        goto 99
 
C NEXTAC
  104   continue
        if (server.gt.0) then
          call SCHED(0.0, STARTA, IDE())
        elseif (A(3).eq.DELUX) then
          call preemp()
        else
          call QUEUE(1, 0.0)
        endif
        goto 99
 
C STARTA
  102   continue
        call SCHED(A(2), ENDACT, IDE())
        server = server - 1
        goto 99
 
C ENDACT
  103   continue
        if (A(3).ne.DELUX) call TALLY(1, A(1))
        call DISPOS
        server = server + 1
 
        if (NQ(2).gt.0) then
          call REMVFQ(2, 1)
          call SCHED(0.0, STARTA, IDE())
        elseif (NQ(1).gt.0) then
          call REMVFQ(1, 1)
          call SCHED(0.0, STARTA, IDE())
        endif
        goto 99

      else
 
        call SUMRY(' ')
        stop 'End of simulation'
 
      endif
      end
